package com.ac.app.web.action.org;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionMapping;
import com.ac.app.dm.PickOrg;
import com.ac.app.web.form.SearchPickOrgForm;
import com.ac.app.web.view.PickOrgView;
import com.caac.core.config.QueryClass;
import com.caac.core.util.Page;
import com.caac.core.web.action.BasePageViewAction;
import com.caac.core.web.action.PageViewForward;
import com.caac.core.web.form.BaseForm;

public class SearchPickOrgAction extends BasePageViewAction {
	private static final String QUERY_NAME = "pkOrgQuery";
    private static final String ORDER_NAME = "pkOrgOrder";
    private static final String VIEW_NAME = "pkOrgView";

	protected PageViewForward doPageViewExecute(ActionMapping mapping,
			BaseForm form, HttpServletRequest request,
			HttpServletResponse response, int pageNo, int pageSize)
			throws Exception {
		SearchPickOrgForm myForm = (SearchPickOrgForm) form;
        QueryClass qc = getQuery(QUERY_NAME);
        Page page = new Page(getBaseManager().getCount(PickOrg.class, qc,
                myForm,
                myForm.isAnd()), pageNo, pageSize);

        List dmList = getBaseManager().getObjects(PickOrg.class, qc, myForm,
                                                  myForm.isAnd(),
                                                  getOrder(ORDER_NAME), page);
        List vList = new ArrayList();
        for (int i = 0; i < dmList.size(); i++) {
        	PickOrg dm = (PickOrg) dmList.get(i);
        	PickOrgView dmView = new PickOrgView();
        	dmView.setDm(dm);
            vList.add(dmView);
        }
        return new PageViewForward(forward(mapping), vList, page,
                                   getSelViewProps(VIEW_NAME), VIEW_NAME,
                                   ORDER_NAME);
	}

}
